package com.kitty.game.wuhun;

import com.kitty.game.hunpo.message.StringIntValue;
import com.kitty.game.hunpo.service.HunPoService;
import com.kitty.game.hunqiao.model.HunQiaoField;
import com.kitty.game.neidan.message.RespNeidanPanelData;
import com.kitty.game.neidan.model.NeidanProp;
import com.kitty.game.neidan.service.NeidanService;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.team.message.RespMsg;
import com.kitty.game.vip.ReqVip;
import com.kitty.game.vip.VipController;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.codec.xf.StanUtils;
import com.kitty.mina.message.MessagePusher;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class WuhunService {
    Logger logger = LoggerFactory.getLogger(WuhunService.class);
   @Autowired
   private WuHunService_ WWuHunService;
    @Autowired
    private RoleService roleService;
    @Autowired
    NeidanService neidanService;
    @RequestMapping
    public void openwuhun(IoSession session, ResWuhunchushi resWuhunchushi) {
        //logger.error("打开武魂");
        Role role = SessionUtils.getRoleBySession(session);
        NeidanProp neidanProp = role.getExtendBox().getNeidanProp();
        RespNeidanPanelData respNeidanPanelData = neidanService.getPanelPropResp(role);
       // ReschushiWH resOpenWH =new ReschushiWH();
        MessagePusher.pushMessage(role, respNeidanPanelData);
        //MessagePusher.pushMessage(session,Buffer);


        WWuHunService.sendPanel(role);

    }
    @RequestMapping
    public void WUHUN_BREAK(IoSession session, ResWhunBREAK resWhunBREAK){
        Role role = SessionUtils.getRoleBySession(session);
        WuHunPoProp wuHunPoProp = WWuHunService.getWuHunPoProp(role);
        //WuHunPoProp
        //wuHunPoProp.getLevel()////////层数
        if (wuHunPoProp.getLevel() >= 9  &&  wuHunPoProp.getLevelInner() >= 6) {
            MessagePusher.pushMessage(session, new RespMsg("已无法再突破！"));
            return;
        }
       int suoxu =  WWuHunService.getStageUpReq(wuHunPoProp.getLevel(), wuHunPoProp.getLevelInner());
        if (suoxu > wuHunPoProp.getWulingzhi()) {
            //武灵值
            MessagePusher.pushMessage(session, new RespMsg("当前武灵值不足以提升，可前往积分商店使用积分购买！"));
            return;
        }

        roleService.subWuling(role,suoxu,false);



       int wh_j=  wuHunPoProp.getLevelInner()+1;
       int wh_c =  wuHunPoProp.getLevel();
      if( wh_j > 9){

          wh_c++;
          wh_j = 0;
          wuHunPoProp.setLevel(wh_c);
          MessagePusher.pushMessage(session, new RespMsg("恭喜，你消耗了#R"+suoxu+"#W点武灵值将武魂提升到了#R"+wh_c+"#W层"));
      }
        wuHunPoProp.setLevelInner(wh_j);
        if( wh_j >0){
            MessagePusher.pushMessage(session, new RespMsg("恭喜，你消耗了#R"+suoxu+"#W点武灵值将你的武魂第#Y"+wh_c+"#W层的小阶段提升到了#R"+wh_j+"#W阶"));
        }
        role.save();
        WWuHunService.calcAddedProp(wuHunPoProp);
        roleService.sendExtraAttribute(role);
       roleService.sendUpdateWuhun(role);
       WWuHunService.sendPanel(role);



    }
    public WuHunPoProp getWuHunProp(Role role) {
        WuHunPoProp wuHunPoProp = role.getExtendBox().getWuHunPoProp();
        if (wuHunPoProp == null) {
            //数据初始化
            wuHunPoProp = new WuHunPoProp();
            role.getExtendBox().setWuHunPoProp(wuHunPoProp);
            wuHunPoProp.setLevel(1);
            wuHunPoProp.setLevelInner(0);
            role.save();
        }

        return wuHunPoProp;
    }

}
